package sjtu.ist.warehouse4ws.dao;

import java.util.List;

import org.hibernate.SQLQuery;
import org.springframework.orm.hibernate3.HibernateTemplate;


import sjtu.ist.warehouse4ws.model.Domainmodel;
import sjtu.ist.warehouse4ws.model.Domainmodelstate;

public class DomainModelStateDaoHibernate extends BaseDaoHibernate<Domainmodelstate> implements DomainModelStateDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<Domainmodelstate> findAllDomainModelStates(String domainModelId) {
		// TODO Auto-generated method stub
		SQLQuery query=getSession().createSQLQuery("select Domainmodelstate.* from Domainmodelstate where Domainmodelstate.domainModelid='"+domainModelId+"'");
		List list=query.addEntity(Domainmodelstate.class).list();
		return list;
	}

	@Override
	public void savaDomainmodelstate(Domainmodelstate domainmodelstate) {
		// TODO Auto-generated method stub
		getHibernateTemplate().setFlushMode(HibernateTemplate.FLUSH_EAGER);
		getHibernateTemplate().saveOrUpdate(domainmodelstate);
	}

	@Override
	public List<Domainmodelstate> getByGroupAndVersion(String groupId, String version) {
		// TODO Auto-generated method stub
		SQLQuery query=getSession().createSQLQuery("select Domainmodelstate.* from Domainmodelstate where Domainmodelstate.groupId=? and versionId=?");
		query.setParameter(0, groupId);
		query.setParameter(1, version);
		List list=query.addEntity(Domainmodelstate.class).list();
		return list;
	}

}
